package com.smarttest.common.util;

import java.util.concurrent.TimeUnit;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

public class LocalCache<T> {
	
	private Cache<String, T> localContentCache;

	public LocalCache(long expireTime) {
		localContentCache = CacheBuilder.newBuilder().expireAfterWrite(expireTime, TimeUnit.SECONDS).build();
	}
	public void removeCache(String key) {
		// 删除该对象到Map中使其缓存
		localContentCache.invalidate(key);
	}
	public void put(String key ,T gpsCard) {
		if(key == null || "".equals(key)){
			return;
		}
		if(gpsCard == null){
			return;
		}
		// 添加该对象到Map中使其缓存
		localContentCache.put(key, gpsCard);
	}
	public T get(String key) {
		return localContentCache.getIfPresent(key);
	}

	public long getCount(){
		return localContentCache.size();
	}

}
